package com.macro.mall.controller.admin;

import com.macro.mall.common.api.ReturnObject;
import com.macro.mall.dto.MinioUploadDto;
import com.macro.mall.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * MinIO对象存储管理Controller
 * Created by macro on 2019/12/25.
 */
@RestController
@Api(tags = "MinioController")
@Tag(name = "MinioController", description = "MinIO对象存储管理")
@RequestMapping("/minio")
public class MinioController {

    @Resource
    private OssService ossService;

    @ApiOperation("文件上传")
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public ReturnObject<MinioUploadDto> upload(@RequestPart("file") MultipartFile file) {
        return new ReturnObject<>(ossService.upload(file));
    }

//    @ApiOperation("文件删除")
//    @RequestMapping(value = "/delete", method = RequestMethod.POST)
//    @ResponseBody
//    public ReturnObject delete(@RequestParam("objectName") String objectName) {
//        try {
//            MinioClient minioClient = MinioClient.builder()
//                    .endpoint(ENDPOINT)
//                    .credentials(ACCESS_KEY,SECRET_KEY)
//                    .build();
//            minioClient.removeObject(RemoveObjectArgs.builder().bucket(BUCKET_NAME).object(objectName).build());
//            return ReturnObject.success(null);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return ReturnObject.failed();
//    }
}
